package cleanstarxchange.server;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class OwnedStock 
{   
	// Primary Key
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long ownedID;
	// Field will be stored in datastore
	@Persistent
	private Long id;
	// Field will be stored in datastore
	@Persistent
	private int quantity;
	// Field will be stored in datastore
	@Persistent
	private double purchasePrice;
	// Field will be stored in datastore
	@Persistent
	private Long uid;
	
	/**
	 * Constructor for owned stock
	 * @param id - ID of the stock being purchased
	 * @param uid - ID of the user purchasing the stock
	 * @param quantity - quantity user is purchasing
	 * @param purchasePrice - price the user is purchasing the stock at
	 */
	public OwnedStock( Long id, Long uid,int quantity, double purchasePrice )
	{
		this.id = id;
		this.uid = uid;
		this.quantity = quantity;
		this.purchasePrice = purchasePrice;
	}
	
	/**
	 * Empty Constructor
	 */
	public OwnedStock(){}
	
	/**
	 * Return the ID (primary key) of the owned stock entity
	 * @return - owned stock ID
	 */
	public Long getOwnedID()
	{
		return ownedID;
	}
	
	/**
	 * Return the user ID of the user who owns the stock
	 * @return - user ID
	 */
	public Long getUid()
	{
		return uid;
	}
	
	/**
	 * Return the ID of the celebrity
	 * @return - stock id
	 */
	public Long getID()
	{
		return id;
	}
	
	/**
	 * Return the number of shares
	 * @return - number of shares
	 */
	public int getQuantity()
	{
		return quantity;
	}
	
	/**
	 * Return the price this owned stock was purchased at
	 * @return - purchase price
	 */
	public double getPurchasePrice()
	{
		return purchasePrice;
	}
	
	/**
	 * Subtract quantity from owned stock entity, used when user is selling stocks
	 * @param q - quantity to subtract
	 */
	public void subQuantity( int q )
	{
		this.quantity -= q;
	}
}

